<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="<%=request.getContextPath()%>/dwr/engine.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/dwr/util.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/dwr/interface/MyDwr.js"></script>
<script type="text/javascript">
function calAdd() {
	var a = dwr.util.getValue("a");
	var b = dwr.util.getValue("b");
	MyDwr.add(parseInt(a),parseInt(b),function(data){
		alert(data);
	});
}

function addAddress() {
	var a = dwr.util.getValue("addressName");
	var data = [{id:a,name:a}];
	dwr.util.addOptions("address",data,"id","name");
}
function initAddress() {
	dwr.util.removeAllOptions();
	var data = [{id:1,name:"北京"},{id:2,name:"天津"},{id:3,name:"上海"}];
	dwr.util.addOptions("address",data,"id","name");
}

function initUser() {
	MyDwr.list(function(data){
		dwr.util.addRows("user",data,cellFuncs,{ escapeHtml:false });
	});
}
var cellFuncs=[
	function(data){return data.id},
	function(data){return data.username},
	function(data){return data.group.name}
];
</script>
</head>
<body>
	<input type="text" id="a"/>+<input type="text" id="b"/><input type="button" value="获取" onclick="calAdd()">
	<br/>
	<select id="address">
	
	</select>
	<input type="button" value="初始化地址" onclick="initAddress()"/>
	<input type="text" id="addressName"/><input type="button" value="添加" onclick="addAddress()"/>
	<table width="600" border="1">
		<thead>
			<tr>
				<td>ID</td>
				<td>username</td>
				<td>groupName</td>
			</tr>
		</thead>
		<tbody id="user">
		</tbody>
	</table>
	
	<input type="button" value="初始化用户" onclick="initUser()"/>
</body>
</html>